from python_baway.common.xcommon import sep


# 使用递归完成以下作业
# 求n-m的累加和
def xsum_from_to(n, m):
    def xsum(x):
        if x == n:
            return n
        else:
            return x + xsum(x - 1)
    return xsum(m)


print(xsum_from_to(51, 100))
print(sum(range(51, 100 + 1)))


# 求n的阶乘
def xfactor(n):
    if n <= 1:
        return 1
    else:
        return n * xfactor(n - 1)


sep()
print('Factor')
for i in range(1, 6 + 1):
    print(i, xfactor(i))


# 猴子每天吃的比前一天的一半还多1个桃，第十天的时候剩一个桃子，问第一天猴子有多少个桃子？
def xpeach(xday):
    if xday > 10 or xday < 1:
        return 0
    elif xday == 10:
        return 1
    else:
        return (xpeach(xday + 1) + 1) * 2


sep()
print('Money and peaches')
for i in range(1 - 3, 10 + 1 + 3):  # 6 days more to test robustness
    print(i, xpeach(i))

